import * as homeApi from '@/api/home.js';

export default {
  namespaced: true,
  state() {
    return {
      categoryList: [],
      bannerList: [],
      newList: [],
    };
  },
  mutations: {
    SET_CATEGORY_LIST(state, newValue) {
      state.categoryList = newValue;
    },
    SET_BANNER(state, newValue) {
      state.bannerList = newValue;
    },
    SET_NEW_LIST(state, newValue) {
      state.newList = newValue;
    },
  },
  actions: {
    async getCategory({ commit }) {
      const res = await homeApi.getCategory();
      commit('SET_CATEGORY_LIST', res);
    },
    async getBanner({ commit }) {
      const res = await homeApi.getBanner();
      commit('SET_BANNER', res);
    },
    async getNew({ commit }) {
      const res = await homeApi.getNew();
      commit('SET_NEW_LIST', res);
    },
  },
};
